home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume4 / snapshot < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  20.0 KB

  1. Path: xanth!mcnc!gatech!cwjcc!hal!ncoast!allbery
  2. From: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  3. Newsgroups: comp.sources.misc
  4. Subject: v04i021: Terminal screen snapshot program
  5. Message-ID: <8808140351.AA12513@rocky2>
  6. Date: 14 Aug 88 03:51:36 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  9. Lines: 800
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 4, Issue 21
  13. Submitted-by: "David MacKenzie" <edf@ROCKY2.ROCKEFELLER.EDU>
  14. Archive-name: snapshot
  15.  
  16. Here is a program that reads the return values of the "transmit line"
  17. function that some terminals provide, and saves them in a file.
  18.  
  19. Currently, it supports only the Wyse 50 and Heath/Zenith 29, but
  20. support for other terminals shouldn't be hard to add.
  21.  
  22. David MacKenzie
  23.  
  24. #! /bin/sh
  25. # This is a shell archive.  Remove anything before this line, then unpack
  26. # it by saving it into a file and typing "sh file".  To overwrite existing
  27. # files, type "sh file -c".  You can also feed this as standard input via
  28. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  29. # will see the following message at the end:
  30. #        "End of archive 1 (of 1)."
  31. # Contents:  MANIFEST Makefile README echo.c h29.c main.c signals.c
  32. #   snapshot.1 snapshot.c snapshot.h wy50.c
  33. # Wrapped by dave@edfdc  on Sat Aug 13 23:44:28 1988
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  37. else
  38. echo shar: Extracting \"'MANIFEST'\" \(455 characters\)
  39. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  40. X   File Name        Archive #    Description
  41. X-----------------------------------------------------------
  42. X MANIFEST                   1    This shipping list
  43. X Makefile                   1    
  44. X README                     1    
  45. X echo.c                     1    
  46. X h29.c                      1    
  47. X main.c                     1    
  48. X signals.c                  1    
  49. X snapshot.1                 1    
  50. X snapshot.c                 1    
  51. X snapshot.h                 1    
  52. X wy50.c                     1    
  53. END_OF_FILE
  54. if test 455 -ne `wc -c <'MANIFEST'`; then
  55.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  56. fi
  57. # end of 'MANIFEST'
  58. fi
  59. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  60.   echo shar: Will not clobber existing file \"'Makefile'\"
  61. else
  62. echo shar: Extracting \"'Makefile'\" \(761 characters\)
  63. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  64. X# Makefile for snapshot.
  65. X# Latest revision: 07/29/88
  66. X
  67. XCFLAGS = -O
  68. XLIBS   =
  69. XDEFS   =
  70. XTARGET = snapshot
  71. XHDRS  = snapshot.h 
  72. XSRCS  = echo.c h29.c main.c signals.c snapshot.c wy50.c 
  73. XOBJS  = echo.o h29.o main.o signals.o snapshot.o wy50.o 
  74. X
  75. X$(TARGET): $(OBJS) $(SRCS) $(HDRS)
  76. X    $(CC) $(CFLAGS) $(DEFS) $(OBJS) -o $(TARGET) $(LIBS)
  77. X    strip $(TARGET)
  78. X
  79. Xecho.o: echo.c 
  80. X    $(CC) $(CFLAGS) $(DEFS) -c echo.c
  81. X
  82. Xh29.o: h29.c 
  83. X    $(CC) $(CFLAGS) $(DEFS) -c h29.c
  84. X
  85. Xmain.o: main.c 
  86. X    $(CC) $(CFLAGS) $(DEFS) -c main.c
  87. X
  88. Xsignals.o: signals.c 
  89. X    $(CC) $(CFLAGS) $(DEFS) -c signals.c
  90. X
  91. Xsnapshot.o: snapshot.c 
  92. X    $(CC) $(CFLAGS) $(DEFS) -c snapshot.c
  93. X
  94. Xwy50.o: wy50.c 
  95. X    $(CC) $(CFLAGS) $(DEFS) -c wy50.c
  96. X
  97. Xclean: $(OBJS)
  98. X    rm -f $(OBJS)
  99. X
  100. Xlint:
  101. X    lint $(SRCS) > LINT.OUT
  102. X
  103. Xkit:
  104. X    makekit -m -p
  105. END_OF_FILE
  106. if test 761 -ne `wc -c <'Makefile'`; then
  107.     echo shar: \"'Makefile'\" unpacked with wrong size!
  108. fi
  109. # end of 'Makefile'
  110. fi
  111. if test -f 'README' -a "${1}" != "-c" ; then 
  112.   echo shar: Will not clobber existing file \"'README'\"
  113. else
  114. echo shar: Extracting \"'README'\" \(2351 characters\)
  115. sed "s/^X//" >'README' <<'END_OF_FILE'
  116. Xsnapshot
  117. X
  118. X08/10/88
  119. X
  120. XThis program gives users of serial terminals some of the capability of
  121. Xthe PC's PrtSc key.
  122. X
  123. XCurrently it supports the Wyse 50 and Heath/Zenith 29 terminals.  I
  124. Xthink that the H29 code also works on H19's.  The Wyse 50 code only
  125. Xworks in 80-column mode; I experimented with the extended cursor
  126. Xpositioning that supports the 132-column mode, but I couldn't get it
  127. Xto work.
  128. X
  129. XInstalling Terminal Definitions
  130. X
  131. XTermcap/terminfo are not used because it would be difficult to coerce
  132. Xthem into dealing with the oddities of producing a screen dump.
  133. XHowever, snapshot is easily extendable, by recompiling, for any
  134. Xterminal that can transmit the contents of the screen.
  135. X
  136. XIssues that must be dealt with include:
  137. X - where must the cursor be in order to transmit a line?  (probably
  138. X   either at the start or end of the line)
  139. X - what is the code to tell the terminal to transmit a line?
  140. X - in what format does it transmit the line?  (does it include special
  141. X   escape sequences?)
  142. X - how is the cursor position saved/restored?  (might be defined as the 
  143. X   sc and rc termcap capabilities.  if the terminal can't save/restore
  144. X   the cursor position, you can try using its "return cursor
  145. X   coordinates" code; I had trouble reading the Wyse 50's cursor
  146. X   position, so I #ifdef'd that code out and just have it return to the
  147. X   bottom of the screen every time)
  148. X
  149. XHere's what you need to do:
  150. X
  151. X1.  Create a file similar to wy50.c and h29.c that defines
  152. Xname_savepos(), name_restorepos(), and name_transline() for the new
  153. Xterminal.  Transmitting a whole screenful at once has been unreliable
  154. Xin my experience, and it precludes specifying starting and ending lines;
  155. Xbut if you want to do it, you can have name_transline() keep a static
  156. Xvariable and be a no-op all but the first time it is called.
  157. X
  158. X2.  Add function declarations and an entry in tdtab[], and increment
  159. XNTD, in main.c
  160. X
  161. X3.  Add the file from step 1. to the Makefile and remake the program.
  162. X
  163. XIf you can figure out a better way to support different terminals, feel
  164. Xfree to change things around!
  165. X
  166. XThe program is designed modularly so that it is easy to replace parts of
  167. Xit, if necessary (e.g. for porting to other OS's), and its functions
  168. Xclean up after themselves so they could be linked in as parts of other
  169. Xprograms.
  170. X
  171. XDavid MacKenzie
  172. Xedf@rocky2.rockefeller.edu (...rutgers!cmcl2!rocky2!edf).
  173. END_OF_FILE
  174. if test 2351 -ne `wc -c <'README'`; then
  175.     echo shar: \"'README'\" unpacked with wrong size!
  176. fi
  177. # end of 'README'
  178. fi
  179. if test -f 'echo.c' -a "${1}" != "-c" ; then 
  180.   echo shar: Will not clobber existing file \"'echo.c'\"
  181. else
  182. echo shar: Extracting \"'echo.c'\" \(526 characters\)
  183. sed "s/^X//" >'echo.c' <<'END_OF_FILE'
  184. X/*
  185. X * echo.c
  186. X */
  187. X
  188. X#include <sgtty.h>
  189. X
  190. X/*
  191. X * Turn echo mode off.  Return 0 if ok, -1 if error.
  192. X */
  193. Xecho_off()
  194. X{
  195. X    struct sgttyb ttybuf;
  196. X
  197. X    if (ioctl(0, TIOCGETP, (char *) &ttybuf) == -1)
  198. X    return -1;
  199. X    ttybuf.sg_flags &= ~ECHO;
  200. X    return ioctl(0, TIOCSETP, (char *) &ttybuf);
  201. X}
  202. X
  203. X/*
  204. X * Turn echo mode on.  Return 0 if ok, -1 if error.
  205. X */
  206. Xecho_on()
  207. X{
  208. X    struct sgttyb ttybuf;
  209. X
  210. X    if (ioctl(0, TIOCGETP, (char *) &ttybuf) == -1)
  211. X    return -1;
  212. X    ttybuf.sg_flags |= ECHO;
  213. X    return ioctl(0, TIOCSETP, (char *) &ttybuf);
  214. X}
  215. END_OF_FILE
  216. if test 526 -ne `wc -c <'echo.c'`; then
  217.     echo shar: \"'echo.c'\" unpacked with wrong size!
  218. fi
  219. # end of 'echo.c'
  220. fi
  221. if test -f 'h29.c' -a "${1}" != "-c" ; then 
  222.   echo shar: Will not clobber existing file \"'h29.c'\"
  223. else
  224. echo shar: Extracting \"'h29.c'\" \(643 characters\)
  225. sed "s/^X//" >'h29.c' <<'END_OF_FILE'
  226. X/*
  227. X * h29.c
  228. X */
  229. X
  230. X/*
  231. X * Save the current cursor position.
  232. X */
  233. Xh29_savepos()
  234. X{
  235. X    printf("\033j");
  236. X}
  237. X
  238. X/*
  239. X * Restore the initial cursor position.
  240. X */
  241. Xh29_restorepos()
  242. X{
  243. X    printf("\033k");
  244. X}
  245. X
  246. X/*
  247. X * Tell the terminal to transmit a line.
  248. X */
  249. Xh29_transline(line)
  250. X    int     line;
  251. X{
  252. X    /* Locate cursor at start of next line. */
  253. X    printf("\033Y%c ", line + 32);
  254. X    /*
  255. X     * Send "transmit line" code.  This will send the whole line, padding to
  256. X     * 80 columns with spaces.  Due to graphics and special mode codes, which
  257. X     * will be sent as well, it could end up being well over 80 characters
  258. X     * long. 
  259. X     */
  260. X    printf("\033^");
  261. X}
  262. END_OF_FILE
  263. if test 643 -ne `wc -c <'h29.c'`; then
  264.     echo shar: \"'h29.c'\" unpacked with wrong size!
  265. fi
  266. # end of 'h29.c'
  267. fi
  268. if test -f 'main.c' -a "${1}" != "-c" ; then 
  269.   echo shar: Will not clobber existing file \"'main.c'\"
  270. else
  271. echo shar: Extracting \"'main.c'\" \(2774 characters\)
  272. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  273. X/*
  274. X * snapshot - make a snapshot of the terminal screen into a file
  275. X *
  276. X * Usage: snapshot [-s startline] [-e endline] destfile
  277. X *        snapshot -l
  278. X *
  279. X * Options:
  280. X * -s   specify alternate line # for start of snapshot
  281. X * -e   specify alternate line # for end of snapshot
  282. X * -l   list known terminal ($TERM) types and quit
  283. X *
  284. X * David MacKenzie
  285. X * Latest revision: 07/29/88
  286. X */
  287. X
  288. X#define ALLOCATE        /* Allocate memory for the global variables. */
  289. X#include <stdio.h>
  290. X#include "snapshot.h"
  291. X
  292. Xextern int
  293. Xwy50_savepos(), wy50_restorepos(), wy50_transline();
  294. Xextern int
  295. Xh29_savepos(), h29_restorepos(), h29_transline();
  296. X
  297. X/* Number of entries in tdtab. */
  298. X#define NTD 2
  299. X
  300. Xstruct termdef tdtab[NTD] = {
  301. X    {
  302. X    {"h29", "z29", "h19", "z19", NULL, NULL},
  303. X    h29_savepos,
  304. X    h29_restorepos,
  305. X    h29_transline,
  306. X    0,
  307. X    24
  308. X    },
  309. X    {
  310. X    {"wy50", "wyse50", "wy50-t", "wyse50-t", NULL, NULL},
  311. X    wy50_savepos,
  312. X    wy50_restorepos,
  313. X    wy50_transline,
  314. X    1,
  315. X    24
  316. X    }
  317. X};
  318. X
  319. Xmain(argc, argv)
  320. X    int     argc;
  321. X    char  **argv;
  322. X{
  323. X    char   *getenv();
  324. X    struct termdef *getdef();
  325. X    extern char *optarg;
  326. X    extern int optind;
  327. X    char   *term;        /* Value of $TERM. */
  328. X    int     start = -1;        /* First line (row) to snap. */
  329. X    int     end = -1;        /* Last line (row) to snap. */
  330. X    register int c;        /* Option character. */
  331. X
  332. X    while ((c = getopt(argc, argv, "s:e:l")) != EOF)
  333. X    switch (c) {
  334. X    case 's':
  335. X        start = atoi(optarg);
  336. X        break;
  337. X    case 'e':
  338. X        end = atoi(optarg);
  339. X        break;
  340. X    case 'l':
  341. X        listknown();
  342. X        exit(0);
  343. X    default:
  344. X        usage(argv[0]);
  345. X    }
  346. X    if (optind != argc - 1)
  347. X    usage(argv[0]);
  348. X
  349. X    term = getenv("TERM");
  350. X    tp = getdef(term);
  351. X    if (!tp) {
  352. X    fprintf(stderr, "%s: Unknown terminal type\n", term);
  353. X    exit(1);
  354. X    }
  355. X    if (start == -1)
  356. X    start = minline;
  357. X    if (end == -1)
  358. X    end = maxline;
  359. X
  360. X    if (snapshot(argv[optind], start, end))
  361. X    exit(1);
  362. X
  363. X    exit(0);
  364. X}
  365. X
  366. X/*
  367. X * If term has a legal value for a known termdef, return a pointer
  368. X * to that termdef, else return NULL.
  369. X */
  370. Xstruct termdef *
  371. Xgetdef(term)
  372. X    register char *term;
  373. X{
  374. X    register int tdi;
  375. X    register int termi;
  376. X
  377. X    for (tdi = 0; tdi < NTD; ++tdi)
  378. X    for (termi = 0; termi < NTERMS && tdtab[tdi].td_terms[termi]; ++termi)
  379. X        if (!strcmp(term, tdtab[tdi].td_terms[termi]))
  380. X        return &tdtab[tdi];
  381. X    return NULL;
  382. X}
  383. X
  384. X/*
  385. X * List the $TERM values that are legal.
  386. X */
  387. Xlistknown()
  388. X{
  389. X    register int tdi;
  390. X    register int termi;
  391. X
  392. X    printf("Known terminal types:\n");
  393. X    for (tdi = 0; tdi < NTD; ++tdi) {
  394. X    for (termi = 0; termi < NTERMS && tdtab[tdi].td_terms[termi]; ++termi)
  395. X        printf("%s ", tdtab[tdi].td_terms[termi]);
  396. X    printf("\n");
  397. X    }
  398. X}
  399. X
  400. Xusage(file)
  401. X    char   *file;
  402. X{
  403. X    fprintf(stderr, "Usage: %s [-s startline] [-e endline] destfile\n", file);
  404. X    fprintf(stderr, "       %s -l\n", file);
  405. X    exit(1);
  406. X}
  407. END_OF_FILE
  408. if test 2774 -ne `wc -c <'main.c'`; then
  409.     echo shar: \"'main.c'\" unpacked with wrong size!
  410. fi
  411. # end of 'main.c'
  412. fi
  413. if test -f 'signals.c' -a "${1}" != "-c" ; then 
  414.   echo shar: Will not clobber existing file \"'signals.c'\"
  415. else
  416. echo shar: Extracting \"'signals.c'\" \(1376 characters\)
  417. sed "s/^X//" >'signals.c' <<'END_OF_FILE'
  418. X/*
  419. X * signals.c
  420. X */
  421. X
  422. X#include <stdio.h>
  423. X#include <signal.h>
  424. X#include "snapshot.h"
  425. X
  426. X#ifndef BADSIG
  427. X#define BADSIG (int (*)()) -1
  428. X#endif
  429. X
  430. X/* pointers to functions returning int */
  431. Xstatic int (*oldint) ();    /* Old value of SIGINT. */
  432. X
  433. X#ifdef SIGTTIN
  434. Xstatic int (*oldttin) ();    /* Old value of SIGTTIN. */
  435. Xstatic int (*oldttou) ();    /* Old value of SIGTTOU. */
  436. X#endif
  437. X
  438. X/*
  439. X * Interrupt signal handler.
  440. X */
  441. X
  442. Xstatic int
  443. Xint_handler()
  444. X{
  445. X    fprintf(stderr, "Interrupted\n");
  446. X    longjmp(sjbuf, -1);
  447. X}
  448. X
  449. X/*
  450. X * Set up signal handlers.  Return 0 if ok, -1 if error.
  451. X */
  452. Xhandlesigs()
  453. X{
  454. X#ifdef SIGTTIN
  455. X    /*
  456. X     * Ignore the signals sent if someone in our process group tries a
  457. X     * background read from/write to the tty. 
  458. X     */
  459. X    if ((oldttin = signal(SIGTTIN, SIG_IGN)) == BADSIG ||
  460. X    (oldttou = signal(SIGTTOU, SIG_IGN)) == BADSIG) {
  461. X    return -1;
  462. X    }
  463. X#endif
  464. X
  465. X    /* if interrupts were being ignored, don't catch them */
  466. X    if ((oldint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
  467. X    if (signal(SIGINT, int_handler) == BADSIG) {
  468. X        return -1;
  469. X    }
  470. X    return 0;
  471. X}
  472. X
  473. X/*
  474. X * Restore original signal values.  Return 0 if ok, -1 if error.
  475. X */
  476. Xrestoresigs()
  477. X{
  478. X    int status = 0;
  479. X    
  480. X#ifdef SIGTTIN
  481. X    if (signal(SIGTTIN, oldttin) == BADSIG || signal(SIGTTOU, oldttou) ==
  482. X    BADSIG) {
  483. X    status = -1;
  484. X    }
  485. X#endif
  486. X    if (signal(SIGINT, oldint) == BADSIG) {
  487. X    status = -1;
  488. X    }
  489. X    return status;
  490. X}
  491. END_OF_FILE
  492. if test 1376 -ne `wc -c <'signals.c'`; then
  493.     echo shar: \"'signals.c'\" unpacked with wrong size!
  494. fi
  495. # end of 'signals.c'
  496. fi
  497. if test -f 'snapshot.1' -a "${1}" != "-c" ; then 
  498.   echo shar: Will not clobber existing file \"'snapshot.1'\"
  499. else
  500. echo shar: Extracting \"'snapshot.1'\" \(784 characters\)
  501. sed "s/^X//" >'snapshot.1' <<'END_OF_FILE'
  502. X.TH SNAPSHOT 1
  503. X.SH NAME
  504. Xsnapshot \- make a snapshot of the terminal screen into a file
  505. X.SH SYNOPSIS
  506. X.B snapshot
  507. X[
  508. X.B \-s start
  509. X] [
  510. X.B \-e end
  511. X]
  512. X.B destfile
  513. X.br
  514. X.B snapshot \-l
  515. X.SH DESCRIPTION
  516. X.I Snapshot
  517. Xmakes a copy of the terminal screen (optionally, only certain lines of it;
  518. Xsee below) in the specified file.  It strips any trailing spaces from the
  519. Xend of each line.
  520. X.PP
  521. XOptions:
  522. X.TP
  523. X.I \-s start
  524. Xuse
  525. X.I start
  526. Xas the starting line instead of the default (usually 0 or 1).
  527. X.TP
  528. X.I \-e end
  529. Xuse
  530. X.I end
  531. Xas the ending line instead of the default (usually 24).
  532. X.TP
  533. X.I \-l
  534. Xlist the known terminal types
  535. X.SH BUGS
  536. XOnly works on certain terminals.  Also, the last character in 80-column
  537. Xwide lines is replaced with a newline so that the file can be easily
  538. Xedited.
  539. X.SH AUTHOR
  540. XDavid MacKenzie
  541. END_OF_FILE
  542. if test 784 -ne `wc -c <'snapshot.1'`; then
  543.     echo shar: \"'snapshot.1'\" unpacked with wrong size!
  544. fi
  545. # end of 'snapshot.1'
  546. fi
  547. if test -f 'snapshot.c' -a "${1}" != "-c" ; then 
  548.   echo shar: Will not clobber existing file \"'snapshot.c'\"
  549. else
  550. echo shar: Extracting \"'snapshot.c'\" \(2430 characters\)
  551. sed "s/^X//" >'snapshot.c' <<'END_OF_FILE'
  552. X/*
  553. X * snapshot.c
  554. X */
  555. X
  556. X#include <stdio.h>
  557. X#include <ctype.h>
  558. X#include "snapshot.h"
  559. X
  560. Xstatic FILE *fp;        /* Output stream. */
  561. X
  562. X/*
  563. X * Make a snapshot of lines start through end of the screen into file. 
  564. X * Return 0 if ok, -1 if error.
  565. X */
  566. Xsnapshot(file, start, end)
  567. X    char   *file;        /* Output file. */
  568. X    int     start,
  569. X            end;        /* First, last lines to copy. */
  570. X{
  571. X    char    buf[300];        /* Contents of one line of the screen. */
  572. X
  573. X    if (start < minline || end > maxline || start > end) {
  574. X    fprintf(stderr, "Illegal line range\n");
  575. X    return -1;
  576. X    }
  577. X    if (!(fp = fopen(file, "w"))) {
  578. X    perror(file);
  579. X    return -1;
  580. X    }
  581. X    if (handlesigs() == -1) {
  582. X        perror("signal");
  583. X    return -1;
  584. X    }
  585. X    if (echo_off() == -1) {
  586. X    perror("ioctl");
  587. X    return -1;
  588. X    }
  589. X    savepos();
  590. X    /*
  591. X     * If we've been interrupted, die gracefully.  The original call to
  592. X     * setjmp() returns 0; int_handler() makes it return -1. setjmp is used
  593. X     * so this function can return -1 on ^C. 
  594. X     */
  595. X    if (setjmp(sjbuf)) {
  596. X    (void) cleanup();
  597. X    return -1;
  598. X    }
  599. X    for (; start <= end; ++start) {
  600. X    transline(start);
  601. X    /* Get null-terminated string with newline stripped. */
  602. X    if (fflush(stdout) == EOF || gets(buf) == NULL) {
  603. X        /* Something weird happened. */
  604. X        fprintf(stderr, "Transmission error\n");
  605. X        (void) cleanup();
  606. X        return -1;
  607. X    }
  608. X    editable(buf);
  609. X    fputs(buf, fp);
  610. X    }
  611. X
  612. X    return cleanup();
  613. X}
  614. X
  615. X/*
  616. X * Remove trailing spaces or any character in the last column.
  617. X */
  618. Xeditable(buf)
  619. X    char   *buf;
  620. X{
  621. X    register char *tmp;
  622. X
  623. X    tmp = buf + strlen(buf) - 1;
  624. X    /* Make the line editable in case it's a full screen wide. */
  625. X    *tmp = '\n';
  626. X    /* Skip past trailing spaces. */
  627. X    while (tmp != buf && isspace(*tmp))
  628. X    --tmp;
  629. X    /*
  630. X     * If we got all the way to the start of the line, it's a blank line.
  631. X     * Otherwise, we're positioned at the last non-space char. 
  632. X     */
  633. X    if (tmp != buf)
  634. X    ++tmp;
  635. X    tmp[0] = '\n';
  636. X    tmp[1] = '\0';
  637. X}
  638. X
  639. X/*
  640. X * Clean up the mess we've made.  Return 0 if ok, -1 if error.
  641. X */
  642. Xcleanup()
  643. X{
  644. X    int     status = 0;
  645. X
  646. X    if (restoresigs() == -1) {
  647. X        perror("signal");
  648. X    status = -1;
  649. X    }
  650. X    if (fclose(fp) == EOF) {
  651. X    fprintf(stderr, "Error closing file\n");
  652. X    status = -1;
  653. X    }
  654. X    if (fflush(stdout) == EOF) {
  655. X    fprintf(stderr, "Error flushing output\n");
  656. X    status = -1;
  657. X    }
  658. X    if (echo_on() == -1) {
  659. X    perror("ioctl");
  660. X    status = -1;
  661. X    }
  662. X    restorepos();
  663. X    return status;
  664. X}
  665. END_OF_FILE
  666. if test 2430 -ne `wc -c <'snapshot.c'`; then
  667.     echo shar: \"'snapshot.c'\" unpacked with wrong size!
  668. fi
  669. # end of 'snapshot.c'
  670. fi
  671. if test -f 'snapshot.h' -a "${1}" != "-c" ; then 
  672.   echo shar: Will not clobber existing file \"'snapshot.h'\"
  673. else
  674. echo shar: Extracting \"'snapshot.h'\" \(961 characters\)
  675. sed "s/^X//" >'snapshot.h' <<'END_OF_FILE'
  676. X/*
  677. X * snapshot.h
  678. X */
  679. X
  680. X#ifdef ALLOCATE
  681. X#define EXTERN
  682. X#define INIT(x) = {x}
  683. X#else
  684. X#define EXTERN extern
  685. X#define INIT(x)
  686. X#endif
  687. X
  688. X#define NTERMS 6        /* Max. # of $TERM values per termdef. */
  689. X
  690. X/*
  691. X * All the info we need to know about a terminal in order to make a
  692. X * snapshot of its screen.
  693. X */
  694. Xstruct termdef {
  695. X    char   *td_terms[NTERMS];    /* Possible $TERM values or NULLs. */
  696. X    int     (*td_savepos) ();    /* Function to save cursor position. */
  697. X    int     (*td_restorepos) ();/* Function to restore cursor position. */
  698. X    int     (*td_transline) ();    /* Function to request 1 line transmit. */
  699. X    int     td_minline;        /* Minimum legal line number. */
  700. X    int     td_maxline;        /* Maximum legal line number. */
  701. X};
  702. X
  703. XEXTERN struct termdef *tp;
  704. X
  705. X#define savepos (*tp->td_savepos)
  706. X#define restorepos (*tp->td_restorepos)
  707. X#define transline (*tp->td_transline)
  708. X#define minline tp->td_minline
  709. X#define maxline tp->td_maxline
  710. X
  711. X#include <setjmp.h>
  712. X
  713. XEXTERN jmp_buf sjbuf;
  714. END_OF_FILE
  715. if test 961 -ne `wc -c <'snapshot.h'`; then
  716.     echo shar: \"'snapshot.h'\" unpacked with wrong size!
  717. fi
  718. # end of 'snapshot.h'
  719. fi
  720. if test -f 'wy50.c' -a "${1}" != "-c" ; then 
  721.   echo shar: Will not clobber existing file \"'wy50.c'\"
  722. else
  723. echo shar: Extracting \"'wy50.c'\" \(1277 characters\)
  724. sed "s/^X//" >'wy50.c' <<'END_OF_FILE'
  725. X/*
  726. X * wy50.c
  727. X */
  728. X
  729. X#include <stdio.h>
  730. X
  731. X/* Define as 1 to restore original cursor position at end. */
  732. X#define RESTORE_POS 0
  733. X
  734. X/* Row and column to return to when finished. */
  735. Xstatic int saver,
  736. X        savec;
  737. X
  738. X/*
  739. X * Save the initial cursor position.
  740. X */
  741. Xwy50_savepos()
  742. X{
  743. X#if RESTORE_POS
  744. X    /* Transmit "send the cursor address" code. */
  745. X    printf("\033?");
  746. X    if (fflush(stdout) == EOF) {
  747. X    fprintf(stderr, "Transmission error\n");
  748. X    (void) cleanup();
  749. X    return -1;
  750. X    }
  751. X    saver = getchar();
  752. X    savec = getchar();
  753. X    /* Discard CR. */
  754. X    (void) getchar();
  755. X#else
  756. X    /* Place cursor on bottom line (row) for neatness. */
  757. X    saver = 24 + 31;
  758. X    savec = 1 + 31;
  759. X#endif
  760. X}
  761. X
  762. X/*
  763. X * Restore the initial cursor position.
  764. X */
  765. Xwy50_restorepos()
  766. X{
  767. X    printf("\033=%c%c", saver, savec);
  768. X}
  769. X
  770. X/*
  771. X * Tell the terminal to transmit a line.
  772. X */
  773. Xwy50_transline(line)
  774. X    int     line;
  775. X{
  776. X    /* Locate cursor at end of next line (row n, column 80). */
  777. X    printf("\033=%c%c", line + 31, 80 + 31);
  778. X    /*
  779. X     * Send "transmit line" code.  This will send the whole line, padding to
  780. X     * 80 columns with spaces.  Due to graphics and special mode codes, which
  781. X     * will be sent as well, it could end up being well over 80 characters
  782. X     * long. 
  783. X     */
  784. X    printf("\033");
  785. X    printf("6");
  786. X}
  787. END_OF_FILE
  788. if test 1277 -ne `wc -c <'wy50.c'`; then
  789.     echo shar: \"'wy50.c'\" unpacked with wrong size!
  790. fi
  791. # end of 'wy50.c'
  792. fi
  793. echo shar: End of archive 1 \(of 1\).
  794. cp /dev/null ark1isdone
  795. MISSING=""
  796. for I in 1 ; do
  797.     if test ! -f ark${I}isdone ; then
  798.     MISSING="${MISSING} ${I}"
  799.     fi
  800. done
  801. if test "${MISSING}" = "" ; then
  802.     echo You have the archive.
  803.     rm -f ark[1-9]isdone
  804. else
  805.     echo You still need to unpack the following archives:
  806.     echo "        " ${MISSING}
  807. fi
  808. ##  End of shell archive.
  809. exit 0
  810.